﻿using System;
using System.Collections.Generic;
using System.Text;
using StackExchange.Redis;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Configuration;

namespace EnterpriseInformation
{
	public class RedisClient
	{
        public IConfiguration Configuration { get; }
		public RedisClient(IConfiguration configuration)
		{
			Configuration = configuration;
		}
		private static Lazy<ConfigurationOptions> ConfigOptions = new Lazy<ConfigurationOptions>(() =>
		{
			var connection = "127.0.0.1:6379,allowAdmin=true,connectTimeout=30000,syncTimeout=5000";
			//var connection = "127.0.0.1:6379,allowAdmin=true,connectTimeout=30000,syncTimeout=5000";
			return ConfigurationOptions.Parse(connection);
		});

		private static Lazy<ConnectionMultiplexer> Connection = new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(ConfigOptions.Value));

		private static ConnectionMultiplexer SafeConn
		{
			get
			{
				return Connection.Value;
			}
		}

		public static IDatabase Database
		{
			get
			{
				return SafeConn.GetDatabase(2);
			}
		}
	}
}
